<template>
  <div class="my-tag">
    <!-- :value="value" 回显 是让input框的value属性的值等于标签输入的数据 -->
    <input v-if="isShowEdit" v-focus class="input" type="text" placeholder="输入标签" @blur="noshow" :value="value" @keyup.enter="Setvalue" />
    <div v-else class="text" @dblclick="changeValue">{{value}}</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isShowEdit: false
    };
  },
  props:{
    value:{
        type:String,
        required:true
    }
  },
  methods: {
    changeValue() {
      this.isShowEdit = true;
    },
    noshow(){
        this.isShowEdit=false
    },
    Setvalue(e){
        if(e.target.value.trim()==''){
            alert('输入标签内容')
            return
        }
        this.$emit('input',e.target.value)
        this.isShowEdit=false
    }
  }
};
</script>

<style  lang="less" scoped>
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>